<?php
/**
 * Created by PhpStorm.
 * User: Vlada
 * Date: 9/15/14
 * Time: 4:28 PM
 */

class LoginController extends BaseController{

    public  function  loginAdmin()
    {
        $input = Input::all();
        $username = $input['username'];
        $password = $input['password'];

        $userdata = array(
            'username' => $username,
            'password' => $password
        );

        if(Auth::attempt($userdata))
        {
            $user = Auth::user();
            $podaci = array(
                'ime'=>$user->ime, 'prezime'=>$user->prezime,
                'id'=>$user->id
            );
            Session::put('ime', $user->ime);
            Session::put('prezime', $user->prezime);
            Session::put('id', $user->id);
            Session::put('tip', 'admin');//$user->tip);
            Session::put('status_ulogovan', true);
            return Response::json($podaci);
        }
        else
        {
            $podaci = array(
                'ime'=>null, 'prezime'=>null,
                'id'=>-1
            );
            return Response::json($podaci);
        }
    }

    public  function  loginUser()
    {
        $input = Input::all();
        $username = $input['username'];
        $password = $input['password'];

        $userdata = array(
            'username' => $username,
            'password' => $password
        );
        //login111
        if(Auth::attempt($userdata))
        {
            $user = Auth::user();
            $podaci = array(
                'ime'=>$user->ime, 'prezime'=>$user->prezime,
                'id'=>$user->id
            );
            return Response::json($podaci);
        }
        else
        {
            $podaci = array(
                'ime'=>null, 'prezime'=>null,
                'id'=>-1
            );
            return Response::json($podaci);
        }


    }
}